package Lee_code;

import java.util.HashMap;

/**
 * @author blh
 * @date 2024年10月18日 16:57
 */
public class Lee_169_1018 {
    public int majorityElement(int[] nums) {
        int len = nums.length;
        int sign = len / 2;
        HashMap<Integer, Integer> seen = new HashMap<>();
        for (int num : nums) {
            seen.put(num, seen.getOrDefault(num, 0) + 1);
        }
        for (Integer i : seen.keySet()) {
            if (seen.get(i) > sign) {
                return i;
            }
        }
        return -1;
    }
}
